//
//  AppDelegate.swift
//  LoopWeibo
//
//  Created by loop安 on 2016/12/6.
//  Copyright © 2016年 loop. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        //注册消息中心,修改根控制器
        registerNotification()
        
        self.window = UIWindow.init(frame: UIScreen.main.bounds)
        
        self.window?.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
        
//        let base = LoopComposeViewController()
        
//        self.window?.rootViewController = base
//        self.window?.rootViewController = LoopUserAccountViewModel.shared.userLogin ? LoopWelcomeViewController() : LoopTabBarController()
        self.window?.rootViewController = LoopTabBarController()
        
        self.window?.makeKeyAndVisible()
        
        JPFPSStatus.sharedInstance().open()
        
        return true
    }

    private func registerNotification(){
        NotificationCenter.default.addObserver(self, selector: #selector(changeRootController), name: NSNotification.Name(kChangeRootController), object: nil)
    }
    
    @objc private func changeRootController(noti:Notification){
        
        self.window?.rootViewController = (noti.object == nil ? LoopTabBarController() : LoopWelcomeViewController())
    }

    deinit {
        NotificationCenter.default.removeObserver(self)
    }
}

